$('document').ready(function() {
	checkNavMenuCollapse();
	$('.sidebar .nav-sidebar .hassubmenu a').click(function(e) {
		var $wrap = $(this).closest('.sidebar .nav-sidebar .hassubmenu');
		var $this = $(this).closest('a');
		if($this.hasClass('itm_1')) {
			toggleNavWrap($wrap);
		}
	});
});

function toggleNavWrap(wrap) {
	wrap.toggleClass('active');
	NavWrap_Action(wrap);
}
function openNavWrap(wrap) {
	wrap.addClass('active');
	NavWrap_Action(wrap);
}
function hideNavWrap(wrap) {
	wrap.removeClass('active');
	NavWrap_Action(wrap);
}
function NavWrap_Action(wrap) {
	var $subs = wrap.find('.nav_subs');
	if($subs.length) {
		if(wrap.hasClass('active')) {
			$subs.slideDown();
		} else {
			$subs.slideUp();
		}
	}
}
function checkNavMenuCollapse() {
	// 判断一级菜单是否选中
	var navActive = $('.hassubmenu.active');
	if(navActive.length) {
		openNavWrap(navActive);
	}
	// 判断二级菜单是否选中
	var subNavActive = $('.hassubmenu .subactive');
	if(subNavActive.length) {
		openNavWrap(subNavActive.closest('.hassubmenu'));
	}
}
